<link rel="stylesheet" href="<?php echo base_url('assets/js/jquery/jquery-ui-1.10.4.custom/css/vader/jquery-ui-1.10.4.custom.min.css'); ?>" />
<script type="text/javascript" src="<?php echo base_url('assets/js/jquery/jquery-ui-1.10.4.custom/js/jquery-ui-1.10.4.custom.min.js'); ?>"></script>
<script type="text/javascript" src="<?php echo base_url('assets/js/admin/load.js'); ?>"></script>
<?php
if ($this->uri->segment(4) == '') {
    $editar = false;
} else {
    $editar = true;
}
$id_objeto = $this->uri->segment(4);
?>

<div class="conteudo">
    <div class="cabecalho">
        <h3>Cadastro de notícias</h3>
    </div>
    <div class="inner no-padding full" >
        <div class="padding30" style="padding-bottom: 0;">
            <form id="form" action="<?php echo site_url('admin/noticia/save/' . $id_objeto); ?>" method="POST">
                <div>
                    Título
                </div>
                <div>
                    <input name="titulo" class="full" type="text" size="60" value="<?php echo $this->input->post('titulo'); ?>" />
                </div>
                <br/>
                <div>
                    Ativo
                </div>
                <div class="left group-box">
                    <label for="ativo">Sim</label>
                    <input id="ativo" name="ativo" type="radio" value="1" <?php if ($this->input->post('ativo') == 1) echo "checked='true'" ?> />
                    <label for="inativo">Não</label>
                    <input id="inativo" name="ativo" type="radio" value="0"<?php if ($this->input->post('ativo') == 0) echo "checked='true'" ?>/>
                </div>
                <br class="clear"/>
                <br class="clear"/>
                <div>
                    Data de Início da Publicação
                </div>
                <?php 
                $data_inicio = $this->input->post('data_inicio_publicacao'); 
                $data_inicio = $data_inicio ? $data_inicio->format('d/m/Y') : '';
                $data_fim = $this->input->post('data_fim_publicacao'); 
                $data_fim = $data_fim ? $data_fim->format('d/m/Y') : '';
                ?>
                <div>
                    <input id="data_inicio_publicacao" name="data_inicio_publicacao" type="text" size="10" value="<?php echo  $data_inicio; ?>" class="calendario" />
                </div>
                <br/>
                <div>
                    Data de Término da Publicação
                </div>
                <div>
                    <input id="data_fim_publicacao" name="data_fim_publicacao" type="text" size="10" value="<?php echo $data_fim; ?>" class="calendario" />
                </div>
                <br/>
                <div>
                    <script type="text/javascript" src="<?php echo base_url('assets/js/tinymce/tinymce.min.js'); ?>"></script>
                    <script type="text/javascript">
                        tinymce.init({
                            selector: "textarea",
                            plugins: [
                                "advlist autolink autosave link image lists charmap print preview hr anchor pagebreak spellchecker",
                                "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
                                "table contextmenu directionality emoticons template textcolor paste fullpage textcolor"
                            ],
                            relative_urls: false,
                            image_list: '<?php echo site_url("admin/upload/image_list"); ?>',
                            toolbar1: "newdocument fullpage | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | styleselect formatselect fontselect fontsizeselect",
                            toolbar2: "cut copy paste | searchreplace | bullist numlist | outdent indent blockquote | undo redo | link unlink anchor image media code | inserttime preview | forecolor backcolor",
                            toolbar3: "table | hr removeformat | subscript superscript | charmap emoticons | print fullscreen | ltr rtl | spellchecker | visualchars visualblocks nonbreaking template pagebreak restoredraft",
                            menubar: false,
                            language: "pt_BR",
                            resize: false,
                            toolbar_items_size: 'small',
                            style_formats: [
                                {title: 'Bold text', inline: 'b'},
                                {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
                                {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
                                {title: 'Example 1', inline: 'span', classes: 'example1'},
                                {title: 'Example 2', inline: 'span', classes: 'example2'},
                                {title: 'Table styles'},
                                {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
                            ],
                            templates: [
                                {title: 'Test template 1', content: 'Test 1'},
                                {title: 'Test template 2', content: 'Test 2'}
                            ]
                        });
                    </script>

                    <textarea name="conteudo" style="width: 100%; height: 500px;">
                        <?php echo $this->input->post('conteudo'); ?>
                    </textarea>
                </div>
            </form>
            <br/>
            <footer class="node-footer" style="text-align: right; padding-bottom: 10px;">
                <ul class="links inline">
                    <li class="comment-add first"><a title="cancelar" href="javascript:resetForm();">Cancelar</a></li>
                    <li class="node-readmore"><a id="upload" title="upload" target="_blank" href="<?php echo site_url('admin/upload/index') ?>">Upload imagem</a></li>
                    <li class="node-readmore last"><a title="salvar" rel="tag" href="javascript:submitForm();">Salvar</a></li>
                </ul>
            </footer>
        </div>
    </div>
</div>
<script type="text/javascript">
    jQuery(function() {
        jQuery('.calendario').datepicker({
            changeMonth: true,
            changeYear: true/*,
             showButtonPanel: true*/
        });
        configuraCalendario();
    });

    function configuraCalendario() {
        jQuery.datepicker.regional['pt-BR'] = {
            closeText: 'Fechar',
            prevText: '&#x3c;Anterior',
            nextText: 'Pr&oacute;ximo&#x3e;',
            currentText: 'Hoje',
            monthNames: ['Janeiro', 'Fevereiro', 'Mar&ccedil;o', 'Abril', 'Maio', 'Junho',
                'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'],
            monthNamesShort: ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun',
                'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'],
            dayNames: ['Domingo', 'Segunda-feira', 'Ter&ccedil;a-feira', 'Quarta-feira', 'Quinta-feira', 'Sexta-feira', 'Sabado'],
            dayNamesShort: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sab'],
            dayNamesMin: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sab'],
            weekHeader: 'Sm',
            dateFormat: 'dd/mm/yy',
            firstDay: 0,
            isRTL: false,
            showMonthAfterYear: false,
            yearSuffix: ''
        };
        jQuery.datepicker.setDefaults(jQuery.datepicker.regional['pt-BR']);
    }
    
    function submitForm() {
        jQuery('#content').val(tinyMCE.get('conteudo').getBody().innerHTML);
        jQuery('#form').submit();
    }

    function resetForm() {
        jQuery('#form')[0].reset();
    }
</script>